package lesson14.protobuf;

import io.netty.channel.*;

/**
 * websocket 字符串处理器<br/>
 * Created on : 2018-01-30 22:51
 * @author lizebin
 */
public class ServerHandler extends SimpleChannelInboundHandler<Sinoxk.Message> {

	@Override
	public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
		Channel channel = ctx.channel();
		System.out.println("客户端连接:" + channel.id().asLongText());
	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Sinoxk.Message msg) throws Exception {
		System.out.println(msg);
	}

	@Override
	public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
		super.handlerRemoved(ctx);
		System.out.println("客户端断开:" + ctx.channel().id().asLongText());
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}
